
import cv2
import os
import time


def save_image(image,name):
    if not os.path.exists("result"):
      os.makedirs("result")
    address = "result/" + name
    cv2.imwrite(address,image)

# 读取视频文件
videoCapture = cv2.VideoCapture("C:/upload/7102.mp4")

# 通过摄像头的方式
# videoCapture=cv2.VideoCapture(1)

success, frame = videoCapture.read()

i = 0
while success :
  success, frame = videoCapture.read()
  
  i = i + 1
  
  ## 每格30帧保存一次图片，最终图片数据集还需要手动审核删除重复图片
  if i % 30 != 0:
    continue
  t = time.time()
  ms = int(round(t * 1000))
  print('save image:',ms)
  save_image(frame,'img_'+ str(ms)+'.jpg')